package SE2;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;

//Max
public class VehicleConfiguration
{
	private String name;
	private String specials;
	private int id;
	private LinkedList<Component> allComponents;
	
	VehicleConfiguration(String p_name, String p_chassis, String p_autoBody, String p_interior, String p_specials, int p_wheels)
	{
		this.name = p_name;
		this.specials = p_specials;
		this.allComponents = new VehicleComponents().getAllComponents();
		
		this.allComponents.add(new Component(getProducerInformation(p_chassis),p_chassis, 1));
		this.allComponents.add(new Component(getProducerInformation(p_autoBody),p_autoBody, 1));
		this.allComponents.add(new Component(getProducerInformation(p_interior),p_interior, 1));
		this.allComponents.add(new Component(getProducerInformation("Michelin-Wheels"),"Michelin-Wheels", 4));
	}
	
	private String getProducerInformation(String nameOfComponent)
	{
		DatabaseConnection db = new DatabaseConnection();
		ResultSet res = db.executeStatement("SELECT * FROM materialatstore, producer WHERE materialatstore.prid = producer.prid AND materialatstore.materialname = '" + nameOfComponent + "';");
		try
		{
			if (res.next())
				return res.getString("name");
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
		return "No Producer found!";
	}
	
	public String getName()
	{
		return name;
	}

	public int getId()
	{
		return id;
	}
	
	public String getSpecials()
	{
		return specials;
	}
	
	public LinkedList<Component> getAllComponents()
	{
		return allComponents;
	}
	
	public void setId(int id)
	{
		this.id = id;
	}
}
